package be.jaisy.adapter.hibernate.extender.util;

import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;

/**
 * @author Stany Blanvalet
 */
public class ManifestParserHelper {

	private static ManifestParserHelper INSTANCE;
	
	private ManifestParserHelper() {
		super();
	}
	
	public static ManifestParserHelper getInstance(){
		if(INSTANCE==null)
			INSTANCE = new ManifestParserHelper();
		return INSTANCE;
	}

	public Map<String, String> getSessionFactoryContribution(Bundle bundle) {
		Map<String, String> map = new HashMap<String, String>();
		String header = (String) bundle.getHeaders().get("HibernateExtender-SessionFactoryContribution");
		if (header != null) {
			String clauses[] = header.split(",");
			for (int i = 0; i < clauses.length; i++) {
				String parts[] = clauses[i].trim().split("\\s*;\\s*");
				if (parts.length == 2)
					map.put(parts[0], parts[1]);
			}
		}
		return map;
	}
	
	public Map<String, String> getDataModelContribution(Bundle bundle) {
		Map<String, String> map = new HashMap<String, String>();
		String header = (String) bundle.getHeaders().get("HibernateExtender-DataModelContribution");
		if (header != null) {
			String clauses[] = header.split(",");
			for (int i = 0; i < clauses.length; i++) {
				String parts[] = clauses[i].trim().split("\\s*;\\s*");
				if (parts.length == 2)
					map.put(parts[0], parts[1]);
			}
		}
		return map;
	}
	
}
